package com.parking.bang.rpc.core.client;

import com.google.common.reflect.Reflection;
import com.parking.bang.rpc.serialize.base.RPCSerializeProtocol;

public class MessageSendExecutor {

	private RPCServerLoader serverLoader = RPCServerLoader.getInstance();

	public MessageSendExecutor() {
	}

	// initial server
	public MessageSendExecutor(String serverAdds, RPCSerializeProtocol serializeProtocol) {
		serverLoader.load(serverAdds, serializeProtocol);
	}

	// dynamic change server
	public void setServerLoader(String serverAdds, RPCSerializeProtocol serializeProtocol) {
		serverLoader.load(serverAdds, serializeProtocol);
	}

	public void stop() {
		serverLoader.unLoad();
	}

	public static <T> T execute(Class<T> rpcInterface) {
		return (T) Reflection.newProxy(rpcInterface, new MessageSendProxy<T>());
	}

	public RPCServerLoader getServerLoader() {
		return serverLoader;
	}

}
